package 剑指offer;


/*
 * Author：江松
 * Date：2023/2/20 16:59
 *
 * 字符串替换
 */

public class Main2 {

    public static String replaceSpace(StringBuffer str){
        StringBuffer sb=new StringBuffer();
        for(int i=0;i<str.length();++i){
            char now=str.charAt(i);
            if(now==' '){
                sb.append("%20");
            }else {
                sb.append(now);
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        StringBuffer str=new StringBuffer("We Are Happy");
        System.out.println(replaceSpace(str));
    }
}
